<?php
class Wxident_model extends CI_Model {

    function __construct()
    {
        parent::__construct();
    }
    
    function get_access_token_by_api(){
    	$api = $this->config->config['WECHAT_API_GET_ACCESS_TOKEN'];
    	$appid = $this->config->config['WECHAT_APPID'];
    	$secret = $this->config->config['WECHAT_SECRET'];
    	$url = sprintf($api, $appid, $secret);
    	$re = @file_get_contents($url);
    	$re_arr = json_decode($re, true);
    	if (isset($re_arr['access_token'])){
	    	$tokenfile = BASEWEBPATH . '/other/accesstoken.txt';
	    	$re_arr['get_time'] = time();
	    	@file_put_contents($tokenfile, json_encode($re_arr));
	    	return $re_arr['access_token'];
    	}else{
    		return false;
    	}
    }
    
    function get_access_token(){
    	$tokenfile = BASEWEBPATH . '/other/accesstoken.txt';
		$re = @file_get_contents($tokenfile);
		$re_arr = json_decode($re, true);
		return $re_arr['access_token'];
    }

}
